<extend name="Public/base"/>

<block name="body">
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>[{$model['title']}] 列表</h2>
    </div>
	<div class="cf">
		<div class="fl">
		<empty name="model.extend">
			<div class="tools">
				<a class="btn" href="{:U('add?model='.$model['id'])}">新 增</a>
				<button class="btn ajax-post confirm" target-form="ids" url="{:U('del?model='.$model['id'])}">删 除</button>
			</div>
		</empty>
		</div>
		<!-- 高级搜索 -->
		<div class="search-form fr cf">
			<!-- <div class="sleft">
				<input type="text" name="paramers" class="search-input" value="{:I('paramers')}" placeholder="请输入词性">
				<a class="sch-btn" href="javascript:;" id="paramers" url="{:U('friendLink/lists','model='.$model['name'],false)}"><i class="btn-search"></i></a>
			</div> -->
			<select name="type" id="site">
				<option selected value="-1">请选择</option>
				<option <if condition="$_GET[type] eq 1">selected</if>  value="1">友情链接</option>
				<option <if condition="$_GET[type] eq 2">selected</if>  value="2">合作伙伴</option>
			</select>
			<div class="sleft">
				<input type="text" name="tag_name" class="search-input" value="{:I('tag_name')}" placeholder="请输入名称">
				<a class="sch-btn" href="javascript:;" id="search" url="{:U('friendLink/lists','model='.$model['name'],false)}"><i class="btn-search"></i></a>
			</div>

		</div>
	</div>


    <!-- 数据列表 -->
    <div class="data-table">
        <div class="data-table table-striped">
            <table>
                <!-- 表头 -->
                <thead>
                    <tr>
                        <th class="row-selected row-selected">
                            <input class="check-all" type="checkbox">
                        </th>
                        <volist name="list_grids" id="field">
	                        <if condition="in_array($field['field'][0],array(sort))">
	                            <th ><a style="color:#fff" href="{:U('friendLink/lists','f='.$field['field'][0])}" id="{$field['field'][0]}">{$field.title}<div >↑↓</div></a></th>
	                        <else/>
	                        	 <th>{$field.title}</th>
	                        </if>
                            
                        </volist>
                    </tr>
                </thead>

                <!-- 列表 -->
                <tbody>
                    <volist name="list_data" id="data">
                        <tr>
                            <td><input class="ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
                            <volist name="list_grids" id="grid" key="k">
                                <td >
                                <if condition="$grid['field'][0] eq 'effective'"><button class="btn ajax-post confirm" target-form="ids" <if condition="get_list_field($data,$grid) eq '启用'">url="{:U('forbid?model='.$model['id'].'&ids='.$data['id'])}<else/>url="{:U('eff?model='.$model['id'].'&ids='.$data['id'])}</if>"></if>{:get_list_field($data,$grid)}<if condition="$grid['field'][0] eq 'effective'"></button></if>
                                </td>
                            	
                            </volist>
                           
                        </tr>
                    </volist>
                   
                </tbody>
            </table>
        </div>
    </div>
    <div class="page">
        {$_page|default=''}
    </div>
    <div id="set_cx_html">
      <form id="cx_form" action="{:U('tags/selectTagsByParamers')}" method ='post'>
      	  <volist name="paramers" id="v">
          <label  title="{$v['paramer_ch']}"><input  type="checkbox" name="paramers[]" value="{$v['paramer_en']}"> {$v['paramer_en']}：{$v['paramer_ch']}</label>
          </volist>
      </form>
    </div>
</block>

<block name="script">
<script type="text/javascript" src="__STATIC__/layer/layer.js"></script>
<script type="text/javascript">
var ajax_status = false;
$(function(){
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        var query2  = $('.search-form').find('select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query+'&' + query2;
        }else{
            url += '?' + query+'?' + query2;
        }
		window.location.href = url;
	});

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });
    $("select").each(function(){
     	 $(this).change(function(){
     		 $("#search").click();
     	 })
    	});

});


$(function(){
    $(document).on( "change", ".wttai_ajax_center input[name='site[]']",function(){
        if (ajax_status) {
             return false;
         }
         var checked = $(this).is(':checked')?1:2;

         var site_id = $(this).attr('site_id');
         var category_id = $(this).val();

         console.log(checked);

         var url = "{:U('Site/setCategory')}";
         var data = {
             "site_id":site_id,
             "category_id":category_id,
             "checked":checked
         };
         $.ajax({
             "url":url,
             "data":data,
             "success":function(data) {
                 console.log(data);
                 ajax_status = false;
             },
             "error":function() {
                 console.log(arguments);
             },
             "dataType":"json"
         });
    }); 
 });

    /*设置词性*/
$(function(){
    $('#set_cx').on('click',function(){
        // 打开模态框
       myDialogindex=layer.open({
          type: 1,
          area: ['800px', 'auto'],
          shade: 0.3, //点击遮罩关闭
          title:'设置词性',
          content: $("#set_cx_html"),
          btn:['确定','取消'],
          yes:function(){
            $('#cx_form').submit();
          },
          no:function(){
            layer.closeAll();
          }

      });
    })	
    if("{$up}"){
    	//alert(12);
 	  $("#{$up}").attr("href","{:U('friendLink/lists',array('f'=>$up,'down'=>1))}");
 	  $("#{$up} div").html('↑')
 	  
    }
    if("{$down}"){
    	//alert(12);
 	  $("#{$down}").attr("href","{:U('friendLink/lists',array('f'=>$down,'up'=>1))}");
 	  $("#{$down} div").html('↓')
 	  //$("#{$down}").append('<div>↓</div>')
 	  
    }
})
</script>
</block>
